import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-02-26
 * Time: 21:00
 */
class KthLargest {
    public PriorityQueue<Integer> heap;
    public int _k;

    public KthLargest(int k, int[] nums) {
        heap = new PriorityQueue<>((a, b) -> a - b);// 小根堆
        _k = k;
        for (int i = 0; i < nums.length; i++) {
            heap.offer(nums[i]);
            if (heap.size() > k) {
                heap.poll();
            }
        }
    }

    public int add(int val) {
        heap.offer(val);
        if (heap.size() > _k) {
            heap.poll();
        }
        return heap.peek();
    }
}

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest obj = new KthLargest(k, nums);
 * int param_1 = obj.add(val);
 */
public class Test2 {
}
